<dom-module id="poly-user-music">
  <template>
    <paper-spinner active$="{{spinnerShow}}"></paper-spinner>
    <h2>My Music</h2>
    <iron-ajax id="ajax" url="" handle-as="json" on-response="handleResponse"></iron-ajax>
    <poly-songs class="with-artist" songs$="{{songs}}"></poly-songs>
  </template>
  <script>
    Polymer({
      is: 'poly-user-music',
      properties: {
        spinnerShow: {
          type: Boolean,
          value: true
        }
      },
      ready: function(){
        this.songs = [];
        window.app.umusic = this;

        this.updateList();
      },
      handleResponse: function(res){
        this.songs = res.detail.response;
        window.app.user_music = this.songs;
        this.spinnerShow = false;
      },
      updateList: function(){
        this.$.ajax.url = "http://poly.local/api/api.php?action=get_user_music";
        this.$.ajax.params = {
          userId: sessionStorage.getItem('id'),
          token: sessionStorage.getItem('token')
        };
        this.$.ajax.generateRequest();
      }
    });
  </script>
</dom-module>
